<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="field[@type = 'datetime' and parent::doctype]">
		<xsl:variable name="is_new" select="parent::doctype/@action = 'create'"/>
		<xsl:variable name="document_field" select="../../document[@doctype_name = current()/parent::doctype/@name]/field[@name = current()/@name]"/>
		<div class="field">
			<label class="title_label" for="{@name}">
				<xsl:value-of select="@title"/>
				<xsl:text>:&#160;</xsl:text>
			</label>
			<xsl:variable name="year">
				<xsl:choose>
					<xsl:when test="$is_new">
						<xsl:value-of select="/root/@year"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="$document_field/@year"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:variable>
			<xsl:variable name="month">
				<xsl:choose>
					<xsl:when test="$is_new">
						<xsl:value-of select="/root/@month"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="$document_field/@month"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:variable>
			<xsl:variable name="day">
				<xsl:choose>
					<xsl:when test="$is_new">
						<xsl:value-of select="/root/@day"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="$document_field/@day"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:variable>
			<select name="{@name}_day" class="left_select-">
				<xsl:for-each select="days_for_select/day">
					<option value="{.}">
						<xsl:choose>
							<xsl:when test="../../../../pass_info/vars/var[@name = concat(current()/../../@name, '_day')] = .">
								<xsl:attribute name="selected">selected</xsl:attribute>
							</xsl:when>
							<xsl:when test="../../../../pass_info/vars/var[@name = concat(current()/../../@name, '_day')]"/>
							<xsl:when test="$day = .">
								<xsl:attribute name="selected">selected</xsl:attribute>
							</xsl:when>
						</xsl:choose>
						<xsl:value-of select="."/>
					</option>
				</xsl:for-each>
			</select>
			<select name="{@name}_month" class="left_select-">
				<xsl:for-each select="months_for_select/month">
					<option value="{.}">
						<xsl:choose>
							<xsl:when test="../../../../pass_info/vars/var[@name = concat(current()/../../@name, '_month')] = .">
								<xsl:attribute name="selected">selected</xsl:attribute>
							</xsl:when>
							<xsl:when test="../../../../pass_info/vars/var[@name = concat(current()/../../@name, '_month')]"/>
							<xsl:when test="$month = .">
								<xsl:attribute name="selected">selected</xsl:attribute>
							</xsl:when>
						</xsl:choose>
						<xsl:call-template name="get_month_name">
							<xsl:with-param name="month_number" select="."/>
							<xsl:with-param name="type" select="'with_day'"/>
						</xsl:call-template>
					</option>
				</xsl:for-each>
			</select>
			<select name="{@name}_year" class="left_select-">
				<xsl:choose>
					<xsl:when test="$document_field/years_for_select">
						<xsl:for-each select="$document_field/years_for_select/year">
							<option value="{.}">
								<xsl:choose>
									<xsl:when test="../../../../pass_info/vars/var[@name = concat(current()/../../@name, '_year')] = .">
										<xsl:attribute name="selected">selected</xsl:attribute>
									</xsl:when>
									<xsl:when test="../../../../pass_info/vars/var[@name = concat(current()/../../@name, '_year')]"/>
									<xsl:when test="$year = .">
										<xsl:attribute name="selected">selected</xsl:attribute>
									</xsl:when>
								</xsl:choose>
								<xsl:value-of select="."/>
							</option>
						</xsl:for-each>
					</xsl:when>
					<xsl:otherwise>
						<xsl:for-each select="years_for_select/year">
							<option value="{.}">
								<xsl:choose>
									<xsl:when test="../../../../pass_info/vars/var[@name = concat(current()/../../@name, '_year')] = .">
										<xsl:attribute name="selected">selected</xsl:attribute>
									</xsl:when>
									<xsl:when test="../../../../pass_info/vars/var[@name = concat(current()/../../@name, '_year')]"/>
									<xsl:when test="$year = .">
										<xsl:attribute name="selected">selected</xsl:attribute>
									</xsl:when>
								</xsl:choose>
								<xsl:value-of select="."/>
							</option>
						</xsl:for-each>
					</xsl:otherwise>
				</xsl:choose>
			</select>
			<xsl:if test="true()">
				<xsl:variable name="hours">
					<xsl:choose>
						<xsl:when test="$is_new">
							<xsl:value-of select="/root/@hours"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="$document_field/@hours"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<xsl:variable name="minutes">
					<xsl:choose>
						<xsl:when test="$is_new">
							<xsl:value-of select="/root/@minutes"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="$document_field/@minutes"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<xsl:variable name="seconds">
					<xsl:choose>
						<xsl:when test="$is_new">
							<xsl:value-of select="/root/@seconds"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="$document_field/@seconds"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<select name="{@name}_hours">
					<xsl:for-each select="hours_for_select/hour">
						<option value="{.}">
							<xsl:choose>
								<xsl:when test="../../../../pass_info/vars/var[@name = concat(current()/../../@name, '_hours')] = .">
									<xsl:attribute name="selected">selected</xsl:attribute>
								</xsl:when>
								<xsl:when test="../../../../pass_info/vars/var[@name = concat(current()/../../@name, '_hours')]"/>
								<xsl:when test="$hours = .">
									<xsl:attribute name="selected">selected</xsl:attribute>
								</xsl:when>
							</xsl:choose>
							<xsl:value-of select="."/>
						</option>
					</xsl:for-each>
				</select>
				<xsl:text>:</xsl:text>
				<select name="{@name}_minutes">
					<xsl:for-each select="minutes_for_select/minute">
						<option value="{.}">
							<xsl:choose>
								<xsl:when test="../../../../pass_info/vars/var[@name = concat(current()/../../@name, '_minutes')] = .">
									<xsl:attribute name="selected">selected</xsl:attribute>
								</xsl:when>
								<xsl:when test="../../../../pass_info/vars/var[@name = concat(current()/../../@name, '_minutes')]"/>
								<xsl:when test="$minutes = .">
									<xsl:attribute name="selected">selected</xsl:attribute>
								</xsl:when>
							</xsl:choose>
							<xsl:value-of select="."/>
						</option>
					</xsl:for-each>
				</select>
				<xsl:text>:</xsl:text>
				<select name="{@name}_seconds">
					<xsl:for-each select="seconds_for_select/second">
						<option value="{.}">
							<xsl:choose>
								<xsl:when test="../../../../pass_info/vars/var[@name = concat(current()/../../@name, '_seconds')] = .">
									<xsl:attribute name="selected">selected</xsl:attribute>
								</xsl:when>
								<xsl:when test="../../../../pass_info/vars/var[@name = concat(current()/../../@name, '_seconds')]"/>
								<xsl:when test="$seconds = .">
									<xsl:attribute name="selected">selected</xsl:attribute>
								</xsl:when>
							</xsl:choose>
							<xsl:value-of select="."/>
						</option>
					</xsl:for-each>
				</select>
			</xsl:if>
			<xsl:apply-templates mode="dtf_error" select="."/>
			<xsl:if test="@comment != ''">
				<div class="comment-">
					<xsl:value-of select="@comment"/>
				</div>
			</xsl:if>
		</div>
	</xsl:template>
</xsl:stylesheet>
